package com.cv.system.controller.audit.dict;

import com.cv.framework.common.enums.CommonStatusEnum;
import com.cv.framework.common.pojo.Result;
import com.cv.framework.common.utils.object.BeanUtils;
import com.cv.system.controller.audit.dict.vo.AuditDictDataRespVO;
import com.cv.system.controller.system.dict.vo.data.DictDataSimpleRespVO;
import com.cv.system.dal.dataobject.dict.DictDataDO;
import com.cv.system.service.dict.DictDataService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

import static com.cv.framework.common.pojo.Result.success;

/**
 * 客服审核平台 - 字典数据
 *
 * @author Charles_XDXD
 */
@Tag(name = "客服审核平台 - 字典数据")
@RestController
@RequestMapping("/system/dict-data")
@Validated
public class AuditDictDataController {

    @Resource
    private DictDataService dictDataService;

    @GetMapping("/type")
    @Operation(summary = "根据字典类型查询字典数据信息")
    @Parameter(name = "type", description = "字典类型", required = true, example = "common_status")
    public Result<List<AuditDictDataRespVO>> getDictDataListByType(@RequestParam("type") String type) {
        List<DictDataDO> list = dictDataService.getDictDataList(
                CommonStatusEnum.ENABLE.getStatus(), type);
        return success(BeanUtils.toBean(list, AuditDictDataRespVO.class));
    }

    @GetMapping(value = {"/list-all-simple", "simple-list"})
    @Operation(summary = "获得全部字典数据列表")
    public Result<List<DictDataSimpleRespVO>> getSimpleDictDataList() {
        List<DictDataDO> list = dictDataService.getDictDataList(
                CommonStatusEnum.ENABLE.getStatus(), null);
        return success(BeanUtils.toBean(list, DictDataSimpleRespVO.class));
    }
}
